package com.fitow.common.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private static int SUCCESS = 1;
    private static int FAILURE = 0;

    private int sysCode;  //如果有系统错误，则具体的错误内容不能展示给用户
    private int code;   //如果有业务错误，则可以展示给用户
    private String msg;
    private String message_en;
    private T data;

    //返回成功
    public static<T> Result<T> success(){
        return new Result(SUCCESS, Integer.valueOf(EnumUtil.OK_200.getCode()), EnumUtil.OK_200.getName(), EnumUtil.OK_200.getName_en(), null);
    }

    //返回成功
    public static<T> Result<T> success(T data){
        return new Result(SUCCESS, Integer.valueOf(EnumUtil.OK_200.getCode()), EnumUtil.OK_200.getName(), EnumUtil.OK_200.getName_en(), data);
    }

    //返回成功
    public static<T> Result<T> success(String message, T data){
        return new Result(SUCCESS, Integer.valueOf(EnumUtil.OK_200.getCode()), message, EnumUtil.OK_200.getName_en(), data);
    }

    //返回业务失败
    public static<T> Result<T> failure(){
        return new Result(SUCCESS, Integer.valueOf(EnumUtil.E_500.getCode()), EnumUtil.E_500.getName(), EnumUtil.E_500.getName_en(), null);
    }

    //返回业务失败
    public static<T> Result<T> failure(String message){
        return new Result(SUCCESS, Integer.valueOf(EnumUtil.E_500.getCode()), message, EnumUtil.E_500.getName_en(), null);
    }

    //返回业务失败
    public static<T> Result<T> failure(EnumUtil enumUtil){
        return new Result(SUCCESS, Integer.valueOf(enumUtil.getCode()), enumUtil.getName(), enumUtil.getName_en(), null);
    }

    //返回业务失败
//    public static<T> Result<T> failure(FitowException fitowException){
//        return new Result(SUCCESS, Integer.valueOf(fitowException.getCode()), fitowException.getMessage(), fitowException.getMessage_en(), null);
//    }

    //返回系统错误
    public static<T> Result<T> sysFailure() {
        return new Result(FAILURE, Integer.valueOf(EnumUtil.E_500.getCode()), EnumUtil.E_500.getName(), EnumUtil.E_500.getName_en(), null);
    }

    //返回系统错误
    public static<T> Result<T> sysFailure(String message) {
        return new Result(FAILURE, Integer.valueOf(EnumUtil.E_500.getCode()), message, EnumUtil.E_500.getName_en(), null);
    }

}
